﻿using ICPFrameLib.Business;
using ICPFrameLib.Attributes;
using XHRPMIS.Common;
using EFFC.Frame.Net.Base.Common;
using EFFC.Frame.Net.Base.Data.Base;
using EFFC.Frame.Net.Module.Extend.EWRA.Attributes;
using EFFC.Frame.Net.Module.Extend.EWRA.Attributes.Validation;
using EFFC.Frame.Net.Unit.DB.Parameters;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using EFFC.Extends.LinqDLR2SQL;
using EFFC.Frame.Net.Unit.DB;
using EFFC.Frame.Net.Base.Data;
using System.IO;
using EFFC.Frame.Net.Base.Constants;
using System.Text.RegularExpressions;
using NPOI.SS.UserModel;
using NPOI.SS.Util;
using NPOI.XSSF.UserModel;
using System.Text;
using ICPFrameLib.Common;
using EFFC.Frame.Net.Unit.DB.Datas;

namespace XHRPMIS.Business.v1._0
{
    public partial class MetaDynamicForm
{
    #region OpenAPI
    [EWRARoute("post", "/md_form/{id}/save")]
    [EWRAEmptyValid("data")]
    [EWRARouteDesc("保存元数据表中的指定数据")]
    [EWRAAddInput("data", "object或者array", @"待修改的数据，格式:
{
    _default_pk:'值',
    column_name1:'值,
    column_name2:'值,
    .....
    column_nameN:'值,
     _subs:{
        sub_uid1:[{col1:值,col2:值,...colN:值}],
        sub_uid2:[{col1:值,col2:值,...colN:值}],
        .....
        sub_uidN:[{col1:值,col2:值,...colN:值}]
    }
}", "无默认值", EFFC.Frame.Net.Base.Constants.RestInputPosition.PostData, false)]
    [EWRAAddInput("fixed_data_express", "string", @"固定更新数据条件表达式，采用DBExpress的栏位表达式写法，传入时采用base64+urlcode编码方式；
表达式中可以使用一些基础变量，如下：
__login_id:当前登录者ID,
__login_name:当前登录者的登录名称
__user_no:登录信息中的userno值,
__no:登录信息中的no值,
__user_name:登录信息中的username值,
__user_type:登录信息中的usertype值,
__role_no:当前登录者系统角色编号，多个,
__role_name:当前登录者系统角色名称，多个,
__now:当前时间，格式yyyy-MM-dd HH:mm:ss
", "无默认值", EFFC.Frame.Net.Base.Constants.RestInputPosition.PostData, true)]
    [EWRAOutputDesc("返回结果", @"{
code:'success-成功，failed-失败',
msg:'提示信息'
}")]
    public object Save(string id)
    {
        string fixed_data_express = ComFunc.UrlDecode(ComFunc.IsBase64Then(PostDataD.fixed_data_express));
        var fixeddata = parseFixedExpress(fixed_data_express);
        var datalist = new List<object>();
        if (PostDataD.data is IEnumerable<object>)
        {
            foreach (object item in PostDataD.data)
            {
                datalist.Add(FrameDLRObject.CreateInstance(item));
            }
        }
        else
        {
            var data = FrameDLRObject.CreateInstance(PostDataD.data);
            datalist.Add(data);
        }
        if (datalist.Count <= 0)
        {
            return new
            {
                code = "failed",
                msg = "待保存的数据不可为空"
            };
        }
        if (fixeddata != null)
        {
            foreach (var item in datalist)
            {
                foreach (var key in fixeddata.Keys)
                {
                    ((FrameDLRObject)item).SetValue(key, fixeddata.GetValue(key));
                }
            }
        }
        var addlist = datalist.Where(w => ComFunc.nvl(((FrameDLRObject)w).GetValue("_default_pk")) == "").ToList();
        var updatelist = datalist.Where(w => ComFunc.nvl(((FrameDLRObject)w).GetValue("_default_pk")) != "").ToList();
        var metaup = DB.NewMetaUnitParameter();
        var up = DB.NewDBUnitParameter();
        BeginTrans();
        dynamic rtn4add = null;
        dynamic rtn4update = null;
        if (addlist.Count > 0)
        {
            rtn4add = DoPost(metaup, up, id, addlist, TokenPayLoad.ID, ComFunc.nvl(TokenPayLoad["username"]), ClientInfo.IP, BoolStd.IsNotBoolThen(Configs["Is_UseLocal"]));
            if (rtn4add.code != "success")
            {
                return rtn4add;
            }
        }
        if (updatelist.Count > 0)
        {
            rtn4update = DoPatch(metaup, up, id, updatelist, TokenPayLoad.ID, ComFunc.nvl(TokenPayLoad["username"]), ClientInfo.IP, BoolStd.IsNotBoolThen(Configs["Is_UseLocal"]));
            if (rtn4update.code != "success")
            {
                RollBack();
                return rtn4update;
            }
        }

        CommitTrans();
        if (datalist.Count == 1)
        {
            return new
            {
                code = "success",
                msg = "保存成功",
                data = new
                {
                    _default_pk = rtn4add != null ? ComFunc.nvl(((IEnumerable<object>)rtn4add.data).First()) : ComFunc.nvl((datalist.First() as FrameDLRObject).GetValue("_default_pk"))
                }
            };
        }
        else
        {
            return new
            {
                code = "success",
                msg = "操作成功"
            };
        }
    }
    [EWRARoute("patch", "/md_form/{id}/{pk}/remove")]
    [EWRARouteDesc("逻辑删除")]
    [EWRAAddInput("id", "string", "元数据表uid", "无默认值", EFFC.Frame.Net.Base.Constants.RestInputPosition.Path, false)]
    [EWRAAddInput("pk", "string", @"待删除的数据的_default_pk值", "无默认值", EFFC.Frame.Net.Base.Constants.RestInputPosition.PostData, false)]
    [EWRAAddInput("fixed_filter_express", "string", @"固定过滤条件表达式，采用DBExpress的$where表达式写法，传入时采用base64+urlcode编码方式；
表达式中可以使用一些基础变量，如下：
__login_id:当前登录者ID,
__login_name:当前登录者的登录名称
__user_no:登录信息中的userno值,
__no:登录信息中的no值,
__user_name:登录信息中的username值,
__user_type:登录信息中的usertype值,
__role_no:当前登录者系统角色编号，多个,
__role_name:当前登录者系统角色名称，多个,
__now:当前时间，格式yyyy-MM-dd HH:mm:ss
", "无默认值", EFFC.Frame.Net.Base.Constants.RestInputPosition.PostData, true)]
    [EWRAAddInput("fixed_data_express", "string", @"固定更新数据条件表达式，采用DBExpress的栏位表达式写法，传入时采用base64+urlcode编码方式；
表达式中可以使用一些基础变量，如下：
__login_id:当前登录者ID,
__login_name:当前登录者的登录名称
__user_no:登录信息中的userno值,
__no:登录信息中的no值,
__user_name:登录信息中的username值,
__user_type:登录信息中的usertype值,
__role_no:当前登录者系统角色编号，多个,
__role_name:当前登录者系统角色名称，多个,
__now:当前时间，格式yyyy-MM-dd HH:mm:ss
", "无默认值", EFFC.Frame.Net.Base.Constants.RestInputPosition.PostData, true)]
    [EWRAOutputDesc("返回结果", @"{
code:'success-成功，failed-失败',
msg:'提示信息'
}")]
    public object LogicDelete(string id, string pk)
    {
        string fixed_filter_express = ComFunc.UrlDecode(ComFunc.IsBase64Then(PostDataD.fixed_filter_express));
        string fixed_data_express = ComFunc.UrlDecode(ComFunc.IsBase64Then(PostDataD.fixed_data_express));

        var where_fixed_filter_express = parseFixedExpress(fixed_filter_express);
        var data = parseFixedExpress(fixed_data_express);

        if (fixed_filter_express != "" && where_fixed_filter_express == null)
        {
            return new
            {
                code = "failed",
                msg = "fixed_filter_express格式不正确"
            };
        }
        if (fixed_data_express != "" && data == null)
        {
            return new
            {
                code = "failed",
                msg = "fixed_orderby_express格式不正确"
            };
        }
        if (data == null) data = FrameDLRObject.CreateInstance();

        data.SetValue("_is_deleted", 1);

        BeginTrans();
        var metaup = DB.NewMetaUnitParameter();
        var up = DB.NewDBUnitParameter();
        var info = MetaDataUtilities.GetAllTables(metaup).Where(w => (w.MetaUID == id || w.MetaName == id) && w.IsCreated).FirstOrDefault();
        if (info == null)
        {
            return new
            {
                code = "failed",
                msg = "元数据表不存在",
            };
        }
        string tablename = info.MetaName;

        var datalist = (from t in DB.LamdaTable(up, tablename, "a")
                        where t._default_pk == pk
                        select t).GetQueryList(up);
        if (datalist.Count <= 0)
        {
            return new
            {
                code = "failed",
                msg = "无该资料"
            };
        }
        FrameDLRObject datainfo = datalist.First();
        if (data.Keys.Where(w => !datainfo.Keys.Contains(w)).Count() > 0)
        {
            return new
            {
                code = "failed",
                msg = "栏位不匹配"
            };
        }
        if (BoolStd.IsNotBoolThen(datainfo.GetValue("_is_deleted")))
        {
            return new
            {
                code = "failed",
                msg = "该资料已删除"
            };
        }

        if (IntStd.IsNotIntThen(datainfo.GetValue("_lock")) == MetaLock.Lock
            || IntStd.IsNotIntThen(datainfo.GetValue("_lock")) == MetaLock.LockDelete
            || IntStd.IsNotIntThen(datainfo.GetValue("_lock")) == MetaLock.LockUpdateDelete)
        {
            return new
            {
                code = "failed",
                msg = "该资料已锁定"
            };
        }
        //查看当前操作是否符合过滤条件的要求
        if (where_fixed_filter_express != null)
        {
            FrameDLRObject express = FrameDLRObject.CreateInstance(@"{
$acttype : 'Query'
                }", EFFC.Frame.Net.Base.Constants.FrameDLRFlags.SensitiveCase);
            express.SetValue("$table", tablename);
            where_fixed_filter_express.SetValue("_default_pk", pk);
            express.SetValue("$where", where_fixed_filter_express);
            var result = DB.Excute(up, express, true);
            if (result.QueryTable.RowLength <= 0)
            {
                return new
                {
                    code = "failed",
                    msg = "当前资料不符合完成操作要求"
                };
            }
        }
        //data栏位类型过滤
        ConvertData2DBType(data, info);
        //增加操作者的信息
        data.SetValue("last_id", TokenPayLoad.ID);
        data.SetValue("last_ip", ClientInfo.IP);
        data.SetValue("last_name", TokenPayLoad["username"]);
        data.SetValue("last_time", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
        DB.QuickUpdate(up, tablename, data, new
        {
            _default_pk = pk
        });

        CommitTrans();
        return new
        {
            code = "success",
            msg = "操作成功"
        };
    }
    [EWRARoute("patch", "/md_form/{id}/{pk}/recover")]
    [EWRARouteDesc("恢复逻辑删除的资料")]
    [EWRAAddInput("id", "string", "元数据表uid", "无默认值", EFFC.Frame.Net.Base.Constants.RestInputPosition.Path, false)]
    [EWRAAddInput("pk", "string", @"待删除的数据的_default_pk值", "无默认值", EFFC.Frame.Net.Base.Constants.RestInputPosition.PostData, false)]
    [EWRAAddInput("fixed_filter_express", "string", @"固定过滤条件表达式，采用DBExpress的$where表达式写法，传入时采用base64+urlcode编码方式；
表达式中可以使用一些基础变量，如下：
__login_id:当前登录者ID,
__login_name:当前登录者的登录名称
__user_no:登录信息中的userno值,
__no:登录信息中的no值,
__user_name:登录信息中的username值,
__user_type:登录信息中的usertype值,
__role_no:当前登录者系统角色编号，多个,
__role_name:当前登录者系统角色名称，多个,
__now:当前时间，格式yyyy-MM-dd HH:mm:ss
", "无默认值", EFFC.Frame.Net.Base.Constants.RestInputPosition.PostData, true)]
    [EWRAAddInput("fixed_data_express", "string", @"固定更新数据条件表达式，采用DBExpress的栏位表达式写法，传入时采用base64+urlcode编码方式；
表达式中可以使用一些基础变量，如下：
__login_id:当前登录者ID,
__login_name:当前登录者的登录名称
__user_no:登录信息中的userno值,
__no:登录信息中的no值,
__user_name:登录信息中的username值,
__user_type:登录信息中的usertype值,
__role_no:当前登录者系统角色编号，多个,
__role_name:当前登录者系统角色名称，多个,
__now:当前时间，格式yyyy-MM-dd HH:mm:ss
", "无默认值", EFFC.Frame.Net.Base.Constants.RestInputPosition.PostData, true)]
    [EWRAOutputDesc("返回结果", @"{
code:'success-成功，failed-失败',
msg:'提示信息'
}")]
    public object LogicRecover(string id, string pk)
    {
        string fixed_filter_express = ComFunc.UrlDecode(ComFunc.IsBase64Then(PostDataD.fixed_filter_express));
        string fixed_data_express = ComFunc.UrlDecode(ComFunc.IsBase64Then(PostDataD.fixed_data_express));

        var where_fixed_filter_express = parseFixedExpress(fixed_filter_express);
        var data = parseFixedExpress(fixed_data_express);

        if (fixed_filter_express != "" && where_fixed_filter_express == null)
        {
            return new
            {
                code = "failed",
                msg = "fixed_filter_express格式不正确"
            };
        }
        if (fixed_data_express != "" && data == null)
        {
            return new
            {
                code = "failed",
                msg = "fixed_orderby_express格式不正确"
            };
        }
        if (data == null) data = FrameDLRObject.CreateInstance();

        data.SetValue("_is_deleted", 0);

        BeginTrans();
        var metaup = DB.NewMetaUnitParameter();
        var up = DB.NewDBUnitParameter();
        var info = MetaDataUtilities.GetAllTables(metaup).Where(w => (w.MetaUID == id || w.MetaName == id) && w.IsCreated).FirstOrDefault();
        if (info == null)
        {
            return new
            {
                code = "failed",
                msg = "元数据表不存在",
            };
        }
        string tablename = info.MetaName;

        var datalist = (from t in DB.LamdaTable(up, tablename, "a")
                        where t._default_pk == pk
                        select t).GetQueryList(up);
        if (datalist.Count <= 0)
        {
            return new
            {
                code = "failed",
                msg = "无该资料"
            };
        }
        FrameDLRObject datainfo = datalist.First();
        if (data.Keys.Where(w => !datainfo.Keys.Contains(w)).Count() > 0)
        {
            return new
            {
                code = "failed",
                msg = "栏位不匹配"
            };
        }
        if (!BoolStd.IsNotBoolThen(datainfo.GetValue("_is_deleted")))
        {
            return new
            {
                code = "failed",
                msg = "该资料已恢复"
            };
        }

        //查看当前操作是否符合过滤条件的要求
        if (where_fixed_filter_express != null)
        {
            FrameDLRObject express = FrameDLRObject.CreateInstance(@"{
$acttype : 'Query'
                }", EFFC.Frame.Net.Base.Constants.FrameDLRFlags.SensitiveCase);
            express.SetValue("$table", tablename);
            where_fixed_filter_express.SetValue("_default_pk", pk);
            express.SetValue("$where", where_fixed_filter_express);
            var result = DB.Excute(up, express, true);
            if (result.QueryTable.RowLength <= 0)
            {
                return new
                {
                    code = "failed",
                    msg = "当前资料不符合完成操作要求"
                };
            }
        }
        //data栏位类型过滤
        ConvertData2DBType(data, info);
        //增加操作者的信息
        data.SetValue("last_id", TokenPayLoad.ID);
        data.SetValue("last_ip", ClientInfo.IP);
        data.SetValue("last_name", TokenPayLoad["username"]);
        data.SetValue("last_time", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
        DB.QuickUpdate(up, tablename, data, new
        {
            _default_pk = pk
        });

        CommitTrans();
        return new
        {
            code = "success",
            msg = "操作成功"
        };
    }

    [EWRARoute("patch", "/md_form/{id}/{pk}/submit")]
    [EWRARouteDesc("提交")]
    [EWRAAddInput("id", "string", "元数据表uid", "无默认值", EFFC.Frame.Net.Base.Constants.RestInputPosition.Path, false)]
    [EWRAAddInput("pk", "string", @"待删除的数据的_default_pk值", "无默认值", EFFC.Frame.Net.Base.Constants.RestInputPosition.PostData, false)]
    [EWRAAddInput("fixed_filter_express", "string", @"固定过滤条件表达式，采用DBExpress的$where表达式写法，传入时采用base64+urlcode编码方式；
表达式中可以使用一些基础变量，如下：
__login_id:当前登录者ID,
__login_name:当前登录者的登录名称
__user_no:登录信息中的userno值,
__no:登录信息中的no值,
__user_name:登录信息中的username值,
__user_type:登录信息中的usertype值,
__role_no:当前登录者系统角色编号，多个,
__role_name:当前登录者系统角色名称，多个,
__now:当前时间，格式yyyy-MM-dd HH:mm:ss
", "无默认值", EFFC.Frame.Net.Base.Constants.RestInputPosition.PostData, true)]
    [EWRAAddInput("fixed_data_express", "string", @"固定更新数据条件表达式，采用DBExpress的栏位表达式写法，传入时采用base64+urlcode编码方式；
表达式中可以使用一些基础变量，如下：
__login_id:当前登录者ID,
__login_name:当前登录者的登录名称
__user_no:登录信息中的userno值,
__no:登录信息中的no值,
__user_name:登录信息中的username值,
__user_type:登录信息中的usertype值,
__role_no:当前登录者系统角色编号，多个,
__role_name:当前登录者系统角色名称，多个,
__now:当前时间，格式yyyy-MM-dd HH:mm:ss
", "无默认值", EFFC.Frame.Net.Base.Constants.RestInputPosition.PostData, true)]
    [EWRAOutputDesc("返回结果", @"{
code:'success-成功，failed-失败',
msg:'提示信息'
}")]
    public object Submit(string id, string pk)
    {
        string fixed_filter_express = ComFunc.UrlDecode(ComFunc.IsBase64Then(PostDataD.fixed_filter_express));
        string fixed_data_express = ComFunc.UrlDecode(ComFunc.IsBase64Then(PostDataD.fixed_data_express));

        var where_fixed_filter_express = parseFixedExpress(fixed_filter_express);
        var data = parseFixedExpress(fixed_data_express);

        if (fixed_filter_express != "" && where_fixed_filter_express == null)
        {
            return new
            {
                code = "failed",
                msg = "fixed_filter_express格式不正确"
            };
        }
        if (fixed_data_express != "" && data == null)
        {
            return new
            {
                code = "failed",
                msg = "fixed_orderby_express格式不正确"
            };
        }
        if (data == null) data = FrameDLRObject.CreateInstance();

        data.SetValue("_status", MetaStatus.Submit);//1为提交
        if (ComFunc.nvl(data.GetValue("_lock")) == "")
            data.SetValue("_lock", MetaLock.LockDelete);//不可删除

        BeginTrans();
        var metaup = DB.NewMetaUnitParameter();
        var up = DB.NewDBUnitParameter();
        var info = MetaDataUtilities.GetAllTables(metaup).Where(w => (w.MetaUID == id || w.MetaName == id) && w.IsCreated).FirstOrDefault();
        if (info == null)
        {
            return new
            {
                code = "failed",
                msg = "元数据表不存在",
            };
        }
        string tablename = info.MetaName;

        var datalist = (from t in DB.LamdaTable(up, tablename, "a")
                        where t._default_pk == pk
                        select t).GetQueryList(up);
        if (datalist.Count <= 0)
        {
            return new
            {
                code = "failed",
                msg = "无该资料"
            };
        }
        //查看当前操作是否符合过滤条件的要求
        if (where_fixed_filter_express != null)
        {
            FrameDLRObject express = FrameDLRObject.CreateInstance(@"{
$acttype : 'Query'
                }", EFFC.Frame.Net.Base.Constants.FrameDLRFlags.SensitiveCase);
            express.SetValue("$table", tablename);
            where_fixed_filter_express.SetValue("_default_pk", pk);
            express.SetValue("$where", where_fixed_filter_express);
            var result = DB.Excute(up, express, true);
            if (result.QueryTable.RowLength <= 0)
            {
                return new
                {
                    code = "failed",
                    msg = "当前资料不符合提交要求"
                };
            }
        }

        FrameDLRObject datainfo = datalist.First();
        if (data.Keys.Where(w => !datainfo.Keys.Contains(w)).Count() > 0)
        {
            return new
            {
                code = "failed",
                msg = "栏位不匹配"
            };
        }
        if (IntStd.IsNotIntThen(datainfo.GetValue("_status")) == MetaStatus.Finish)
        {
            return new
            {
                code = "failed",
                msg = "该资料已完成"
            };
        }
        if (IntStd.IsNotIntThen(datainfo.GetValue("_status")) == MetaStatus.Stop)
        {
            return new
            {
                code = "failed",
                msg = "该资料已终止"
            };
        }
        if (IntStd.IsNotIntThen(datainfo.GetValue("_lock")) == MetaLock.Lock)
        {
            return new
            {
                code = "failed",
                msg = "该资料已锁定"
            };
        }
        //data栏位类型过滤
        ConvertData2DBType(data, info);
        //增加操作者的信息
        data.SetValue("last_id", TokenPayLoad.ID);
        data.SetValue("last_ip", ClientInfo.IP);
        data.SetValue("last_name", TokenPayLoad["username"]);
        data.SetValue("last_time", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
        DB.QuickUpdate(up, tablename, data, new
        {
            _default_pk = pk
        });

        CommitTrans();
        return new
        {
            code = "success",
            msg = "操作成功"
        };
    }
    [EWRARoute("patch", "/md_form/{id}/{pk}/pass")]
    [EWRARouteDesc("通过")]
    [EWRAAddInput("id", "string", "元数据表uid", "无默认值", EFFC.Frame.Net.Base.Constants.RestInputPosition.Path, false)]
    [EWRAAddInput("pk", "string", @"待删除的数据的_default_pk值", "无默认值", EFFC.Frame.Net.Base.Constants.RestInputPosition.PostData, false)]
    [EWRAAddInput("fixed_filter_express", "string", @"固定过滤条件表达式，采用DBExpress的$where表达式写法，传入时采用base64+urlcode编码方式；
表达式中可以使用一些基础变量，如下：
__login_id:当前登录者ID,
__login_name:当前登录者的登录名称
__user_no:登录信息中的userno值,
__no:登录信息中的no值,
__user_name:登录信息中的username值,
__user_type:登录信息中的usertype值,
__role_no:当前登录者系统角色编号，多个,
__role_name:当前登录者系统角色名称，多个,
__now:当前时间，格式yyyy-MM-dd HH:mm:ss
", "无默认值", EFFC.Frame.Net.Base.Constants.RestInputPosition.PostData, true)]
    [EWRAAddInput("fixed_data_express", "string", @"固定更新数据条件表达式，采用DBExpress的栏位表达式写法，传入时采用base64+urlcode编码方式；
表达式中可以使用一些基础变量，如下：
__login_id:当前登录者ID,
__login_name:当前登录者的登录名称
__user_no:登录信息中的userno值,
__no:登录信息中的no值,
__user_name:登录信息中的username值,
__user_type:登录信息中的usertype值,
__role_no:当前登录者系统角色编号，多个,
__role_name:当前登录者系统角色名称，多个,
__now:当前时间，格式yyyy-MM-dd HH:mm:ss
", "无默认值", EFFC.Frame.Net.Base.Constants.RestInputPosition.PostData, true)]
    [EWRAOutputDesc("返回结果", @"{
code:'success-成功，failed-失败',
msg:'提示信息'
}")]
    public object Pass(string id, string pk)
    {
        string fixed_filter_express = ComFunc.UrlDecode(ComFunc.IsBase64Then(PostDataD.fixed_filter_express));
        string fixed_data_express = ComFunc.UrlDecode(ComFunc.IsBase64Then(PostDataD.fixed_data_express));

        var where_fixed_filter_express = parseFixedExpress(fixed_filter_express);
        var data = parseFixedExpress(fixed_data_express);

        if (fixed_filter_express != "" && where_fixed_filter_express == null)
        {
            return new
            {
                code = "failed",
                msg = "fixed_filter_express格式不正确"
            };
        }
        if (fixed_data_express != "" && data == null)
        {
            return new
            {
                code = "failed",
                msg = "fixed_orderby_express格式不正确"
            };
        }
        if (data == null) data = FrameDLRObject.CreateInstance();

        data.SetValue("_status", MetaStatus.Pass);
        if (ComFunc.nvl(data.GetValue("_lock")) == "")
            data.SetValue("_lock", MetaLock.LockDelete);

        BeginTrans();
        var metaup = DB.NewMetaUnitParameter();
        var up = DB.NewDBUnitParameter();
        var info = MetaDataUtilities.GetAllTables(metaup).Where(w => (w.MetaUID == id || w.MetaName == id) && w.IsCreated).FirstOrDefault();
        if (info == null)
        {
            return new
            {
                code = "failed",
                msg = "元数据表不存在",
            };
        }
        string tablename = info.MetaName;

        var datalist = (from t in DB.LamdaTable(up, tablename, "a")
                        where t._default_pk == pk
                        select t).GetQueryList(up);
        if (datalist.Count <= 0)
        {
            return new
            {
                code = "failed",
                msg = "无该资料"
            };
        }
        FrameDLRObject datainfo = datalist.First();
        if (data.Keys.Where(w => !datainfo.Keys.Contains(w)).Count() > 0)
        {
            return new
            {
                code = "failed",
                msg = "栏位不匹配"
            };
        }
        if (IntStd.IsNotIntThen(datainfo.GetValue("_status")) == MetaStatus.Finish)
        {
            return new
            {
                code = "failed",
                msg = "该资料已完成"
            };
        }
        if (IntStd.IsNotIntThen(datainfo.GetValue("_status")) == MetaStatus.Stop)
        {
            return new
            {
                code = "failed",
                msg = "该资料已终止"
            };
        }
        if (IntStd.IsNotIntThen(datainfo.GetValue("_lock")) == MetaLock.Lock)
        {
            return new
            {
                code = "failed",
                msg = "该资料已锁定"
            };
        }
        //查看当前操作是否符合过滤条件的要求
        if (where_fixed_filter_express != null)
        {
            FrameDLRObject express = FrameDLRObject.CreateInstance(@"{
$acttype : 'Query'
                }", EFFC.Frame.Net.Base.Constants.FrameDLRFlags.SensitiveCase);
            express.SetValue("$table", tablename);
            where_fixed_filter_express.SetValue("_default_pk", pk);
            express.SetValue("$where", where_fixed_filter_express);
            var result = DB.Excute(up, express, true);
            if (result.QueryTable.RowLength <= 0)
            {
                return new
                {
                    code = "failed",
                    msg = "当前资料不符合操作要求"
                };
            }
        }
        //data栏位类型过滤
        ConvertData2DBType(data, info);
        //增加操作者的信息
        data.SetValue("last_id", TokenPayLoad.ID);
        data.SetValue("last_ip", ClientInfo.IP);
        data.SetValue("last_name", TokenPayLoad["username"]);
        data.SetValue("last_time", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
        DB.QuickUpdate(up, tablename, data, new
        {
            _default_pk = pk
        });

        CommitTrans();
        return new
        {
            code = "success",
            msg = "操作成功"
        };
    }
    [EWRARoute("patch", "/md_form/{id}/{pk}/reject")]
    [EWRARouteDesc("驳回")]
    [EWRAAddInput("id", "string", "元数据表uid", "无默认值", EFFC.Frame.Net.Base.Constants.RestInputPosition.Path, false)]
    [EWRAAddInput("pk", "string", @"待删除的数据的_default_pk值", "无默认值", EFFC.Frame.Net.Base.Constants.RestInputPosition.PostData, false)]
    [EWRAAddInput("fixed_filter_express", "string", @"固定过滤条件表达式，采用DBExpress的$where表达式写法，传入时采用base64+urlcode编码方式；
表达式中可以使用一些基础变量，如下：
__login_id:当前登录者ID,
__login_name:当前登录者的登录名称
__user_no:登录信息中的userno值,
__no:登录信息中的no值,
__user_name:登录信息中的username值,
__user_type:登录信息中的usertype值,
__role_no:当前登录者系统角色编号，多个,
__role_name:当前登录者系统角色名称，多个,
__now:当前时间，格式yyyy-MM-dd HH:mm:ss
", "无默认值", EFFC.Frame.Net.Base.Constants.RestInputPosition.PostData, true)]
    [EWRAAddInput("fixed_data_express", "string", @"固定更新数据条件表达式，采用DBExpress的栏位表达式写法，传入时采用base64+urlcode编码方式；
表达式中可以使用一些基础变量，如下：
__login_id:当前登录者ID,
__login_name:当前登录者的登录名称
__user_no:登录信息中的userno值,
__no:登录信息中的no值,
__user_name:登录信息中的username值,
__user_type:登录信息中的usertype值,
__role_no:当前登录者系统角色编号，多个,
__role_name:当前登录者系统角色名称，多个,
__now:当前时间，格式yyyy-MM-dd HH:mm:ss
", "无默认值", EFFC.Frame.Net.Base.Constants.RestInputPosition.PostData, true)]
    [EWRAOutputDesc("返回结果", @"{
code:'success-成功，failed-失败',
msg:'提示信息'
}")]
    public object Reject(string id, string pk)
    {
        string fixed_filter_express = ComFunc.UrlDecode(ComFunc.IsBase64Then(PostDataD.fixed_filter_express));
        string fixed_data_express = ComFunc.UrlDecode(ComFunc.IsBase64Then(PostDataD.fixed_data_express));

        var where_fixed_filter_express = parseFixedExpress(fixed_filter_express);
        var data = parseFixedExpress(fixed_data_express);

        if (fixed_filter_express != "" && where_fixed_filter_express == null)
        {
            return new
            {
                code = "failed",
                msg = "fixed_filter_express格式不正确"
            };
        }
        if (fixed_data_express != "" && data == null)
        {
            return new
            {
                code = "failed",
                msg = "fixed_orderby_express格式不正确"
            };
        }
        if (data == null) data = FrameDLRObject.CreateInstance();

        data.SetValue("_status", MetaStatus.Reject);//1为通过
        if (ComFunc.nvl(data.GetValue("_lock")) == "")
            data.SetValue("_lock", MetaLock.UnLock);

        BeginTrans();
        var metaup = DB.NewMetaUnitParameter();
        var up = DB.NewDBUnitParameter();
        var info = MetaDataUtilities.GetAllTables(metaup).Where(w => (w.MetaUID == id || w.MetaName == id) && w.IsCreated).FirstOrDefault();
        if (info == null)
        {
            return new
            {
                code = "failed",
                msg = "元数据表不存在",
            };
        }
        string tablename = info.MetaName;

        var datalist = (from t in DB.LamdaTable(up, tablename, "a")
                        where t._default_pk == pk
                        select t).GetQueryList(up);
        if (datalist.Count <= 0)
        {
            return new
            {
                code = "failed",
                msg = "无该资料"
            };
        }
        FrameDLRObject datainfo = datalist.First();
        if (data.Keys.Where(w => !datainfo.Keys.Contains(w)).Count() > 0)
        {
            return new
            {
                code = "failed",
                msg = "栏位不匹配"
            };
        }
        if (IntStd.IsNotIntThen(datainfo.GetValue("_status")) == MetaStatus.Finish)
        {
            return new
            {
                code = "failed",
                msg = "该资料已完成"
            };
        }
        if (IntStd.IsNotIntThen(datainfo.GetValue("_status")) == MetaStatus.Stop)
        {
            return new
            {
                code = "failed",
                msg = "该资料已终止"
            };
        }
        if (IntStd.IsNotIntThen(datainfo.GetValue("_lock")) == MetaLock.Lock)
        {
            return new
            {
                code = "failed",
                msg = "该资料已锁定"
            };
        }
        //查看当前操作是否符合过滤条件的要求
        if (where_fixed_filter_express != null)
        {
            FrameDLRObject express = FrameDLRObject.CreateInstance(@"{
$acttype : 'Query'
                }", EFFC.Frame.Net.Base.Constants.FrameDLRFlags.SensitiveCase);
            express.SetValue("$table", tablename);
            where_fixed_filter_express.SetValue("_default_pk", pk);
            express.SetValue("$where", where_fixed_filter_express);
            var result = DB.Excute(up, express, true);
            if (result.QueryTable.RowLength <= 0)
            {
                return new
                {
                    code = "failed",
                    msg = "当前资料不符合操作要求"
                };
            }
        }
        //data栏位类型过滤
        ConvertData2DBType(data, info);
        //增加操作者的信息
        data.SetValue("last_id", TokenPayLoad.ID);
        data.SetValue("last_ip", ClientInfo.IP);
        data.SetValue("last_name", TokenPayLoad["username"]);
        data.SetValue("last_time", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
        DB.QuickUpdate(up, tablename, data, new
        {
            _default_pk = pk
        });

        CommitTrans();
        return new
        {
            code = "success",
            msg = "操作成功"
        };
    }
    [EWRARoute("patch", "/md_form/{id}/{pk}/finish")]
    [EWRARouteDesc("完成")]
    [EWRAAddInput("id", "string", "元数据表uid", "无默认值", EFFC.Frame.Net.Base.Constants.RestInputPosition.Path, false)]
    [EWRAAddInput("pk", "string", @"待删除的数据的_default_pk值", "无默认值", EFFC.Frame.Net.Base.Constants.RestInputPosition.PostData, false)]
    [EWRAAddInput("fixed_filter_express", "string", @"固定过滤条件表达式，采用DBExpress的$where表达式写法，传入时采用base64+urlcode编码方式；
表达式中可以使用一些基础变量，如下：
__login_id:当前登录者ID,
__login_name:当前登录者的登录名称
__user_no:登录信息中的userno值,
__no:登录信息中的no值,
__user_name:登录信息中的username值,
__user_type:登录信息中的usertype值,
__role_no:当前登录者系统角色编号，多个,
__role_name:当前登录者系统角色名称，多个,
__now:当前时间，格式yyyy-MM-dd HH:mm:ss
", "无默认值", EFFC.Frame.Net.Base.Constants.RestInputPosition.PostData, true)]
    [EWRAAddInput("fixed_data_express", "string", @"固定更新数据条件表达式，采用DBExpress的栏位表达式写法，传入时采用base64+urlcode编码方式；
表达式中可以使用一些基础变量，如下：
__login_id:当前登录者ID,
__login_name:当前登录者的登录名称
__user_no:登录信息中的userno值,
__no:登录信息中的no值,
__user_name:登录信息中的username值,
__user_type:登录信息中的usertype值,
__role_no:当前登录者系统角色编号，多个,
__role_name:当前登录者系统角色名称，多个,
__now:当前时间，格式yyyy-MM-dd HH:mm:ss
", "无默认值", EFFC.Frame.Net.Base.Constants.RestInputPosition.PostData, true)]
    [EWRAOutputDesc("返回结果", @"{
code:'success-成功，failed-失败',
msg:'提示信息'
}")]
    public object Finish(string id, string pk)
    {
        string fixed_filter_express = ComFunc.UrlDecode(ComFunc.IsBase64Then(PostDataD.fixed_filter_express));
        string fixed_data_express = ComFunc.UrlDecode(ComFunc.IsBase64Then(PostDataD.fixed_data_express));

        var where_fixed_filter_express = parseFixedExpress(fixed_filter_express);
        var data = parseFixedExpress(fixed_data_express);

        if (fixed_filter_express != "" && where_fixed_filter_express == null)
        {
            return new
            {
                code = "failed",
                msg = "fixed_filter_express格式不正确"
            };
        }
        if (fixed_data_express != "" && data == null)
        {
            return new
            {
                code = "failed",
                msg = "fixed_orderby_express格式不正确"
            };
        }
        if (data == null) data = FrameDLRObject.CreateInstance();

        data.SetValue("_status", MetaStatus.Finish);
        data.SetValue("_lock", MetaLock.Lock);

        BeginTrans();
        var metaup = DB.NewMetaUnitParameter();
        var up = DB.NewDBUnitParameter();
        var info = MetaDataUtilities.GetAllTables(metaup).Where(w => (w.MetaUID == id || w.MetaName == id) && w.IsCreated).FirstOrDefault();
        if (info == null)
        {
            return new
            {
                code = "failed",
                msg = "元数据表不存在",
            };
        }
        string tablename = info.MetaName;

        var datalist = (from t in DB.LamdaTable(up, tablename, "a")
                        where t._default_pk == pk
                        select t).GetQueryList(up);
        if (datalist.Count <= 0)
        {
            return new
            {
                code = "failed",
                msg = "无该资料"
            };
        }
        FrameDLRObject datainfo = datalist.First();
        if (data.Keys.Where(w => !datainfo.Keys.Contains(w)).Count() > 0)
        {
            return new
            {
                code = "failed",
                msg = "栏位不匹配"
            };
        }
        if (IntStd.IsNotIntThen(datainfo.GetValue("_status")) == MetaStatus.Finish)
        {
            return new
            {
                code = "failed",
                msg = "该资料已完成"
            };
        }
        if (IntStd.IsNotIntThen(datainfo.GetValue("_status")) == MetaStatus.Stop)
        {
            return new
            {
                code = "failed",
                msg = "该资料已终止"
            };
        }
        if (IntStd.IsNotIntThen(datainfo.GetValue("_lock")) == MetaLock.Lock)
        {
            return new
            {
                code = "failed",
                msg = "该资料已锁定"
            };
        }
        //查看当前操作是否符合过滤条件的要求
        if (where_fixed_filter_express != null)
        {
            FrameDLRObject express = FrameDLRObject.CreateInstance(@"{
$acttype : 'Query'
                }", EFFC.Frame.Net.Base.Constants.FrameDLRFlags.SensitiveCase);
            express.SetValue("$table", tablename);
            where_fixed_filter_express.SetValue("_default_pk", pk);
            express.SetValue("$where", where_fixed_filter_express);
            var result = DB.Excute(up, express, true);
            if (result.QueryTable.RowLength <= 0)
            {
                return new
                {
                    code = "failed",
                    msg = "当前资料不符合完成操作要求"
                };
            }
        }
        //data栏位类型过滤
        ConvertData2DBType(data, info);
        //增加操作者的信息
        data.SetValue("last_id", TokenPayLoad.ID);
        data.SetValue("last_ip", ClientInfo.IP);
        data.SetValue("last_name", TokenPayLoad["username"]);
        data.SetValue("last_time", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
        DB.QuickUpdate(up, tablename, data, new
        {
            _default_pk = pk
        });

        CommitTrans();
        return new
        {
            code = "success",
            msg = "操作成功"
        };
    }
    [EWRARoute("patch", "/md_form/{id}/{pk}/stop")]
    [EWRARouteDesc("终止")]
    [EWRAAddInput("id", "string", "元数据表uid", "无默认值", EFFC.Frame.Net.Base.Constants.RestInputPosition.Path, false)]
    [EWRAAddInput("pk", "string", @"待删除的数据的_default_pk值", "无默认值", EFFC.Frame.Net.Base.Constants.RestInputPosition.PostData, false)]
    [EWRAAddInput("fixed_filter_express", "string", @"固定过滤条件表达式，采用DBExpress的$where表达式写法，传入时采用base64+urlcode编码方式；
表达式中可以使用一些基础变量，如下：
__login_id:当前登录者ID,
__login_name:当前登录者的登录名称
__user_no:登录信息中的userno值,
__no:登录信息中的no值,
__user_name:登录信息中的username值,
__user_type:登录信息中的usertype值,
__role_no:当前登录者系统角色编号，多个,
__role_name:当前登录者系统角色名称，多个,
__now:当前时间，格式yyyy-MM-dd HH:mm:ss
", "无默认值", EFFC.Frame.Net.Base.Constants.RestInputPosition.PostData, true)]
    [EWRAAddInput("fixed_data_express", "string", @"固定更新数据条件表达式，采用DBExpress的栏位表达式写法，传入时采用base64+urlcode编码方式；
表达式中可以使用一些基础变量，如下：
__login_id:当前登录者ID,
__login_name:当前登录者的登录名称
__user_no:登录信息中的userno值,
__no:登录信息中的no值,
__user_name:登录信息中的username值,
__user_type:登录信息中的usertype值,
__role_no:当前登录者系统角色编号，多个,
__role_name:当前登录者系统角色名称，多个,
__now:当前时间，格式yyyy-MM-dd HH:mm:ss
", "无默认值", EFFC.Frame.Net.Base.Constants.RestInputPosition.PostData, true)]
    [EWRAOutputDesc("返回结果", @"{
code:'success-成功，failed-失败',
msg:'提示信息'
}")]
    public object Stop(string id, string pk)
    {
        string fixed_filter_express = ComFunc.UrlDecode(ComFunc.IsBase64Then(PostDataD.fixed_filter_express));
        string fixed_data_express = ComFunc.UrlDecode(ComFunc.IsBase64Then(PostDataD.fixed_data_express));

        var where_fixed_filter_express = parseFixedExpress(fixed_filter_express);
        var data = parseFixedExpress(fixed_data_express);

        if (fixed_filter_express != "" && where_fixed_filter_express == null)
        {
            return new
            {
                code = "failed",
                msg = "fixed_filter_express格式不正确"
            };
        }
        if (fixed_data_express != "" && data == null)
        {
            return new
            {
                code = "failed",
                msg = "fixed_orderby_express格式不正确"
            };
        }
        if (data == null) data = FrameDLRObject.CreateInstance();

        data.SetValue("_status", MetaStatus.Stop);//0-保存，1-提交，2-完成，3-通过，4-驳回，5-终止
        data.SetValue("_lock", MetaLock.Lock);

        BeginTrans();
        var metaup = DB.NewMetaUnitParameter();
        var up = DB.NewDBUnitParameter();
        var info = MetaDataUtilities.GetAllTables(metaup).Where(w => (w.MetaUID == id || w.MetaName == id) && w.IsCreated).FirstOrDefault();
        if (info == null)
        {
            return new
            {
                code = "failed",
                msg = "元数据表不存在",
            };
        }
        string tablename = info.MetaName;

        var datalist = (from t in DB.LamdaTable(up, tablename, "a")
                        where t._default_pk == pk
                        select t).GetQueryList(up);
        if (datalist.Count <= 0)
        {
            return new
            {
                code = "failed",
                msg = "无该资料"
            };
        }
        FrameDLRObject datainfo = datalist.First();
        if (data.Keys.Where(w => !datainfo.Keys.Contains(w)).Count() > 0)
        {
            return new
            {
                code = "failed",
                msg = "栏位不匹配"
            };
        }
        if (IntStd.IsNotIntThen(datainfo.GetValue("_status")) == MetaStatus.Finish)
        {
            return new
            {
                code = "failed",
                msg = "该资料已完成"
            };
        }
        if (IntStd.IsNotIntThen(datainfo.GetValue("_status")) == MetaStatus.Stop)
        {
            return new
            {
                code = "failed",
                msg = "该资料已终止"
            };
        }
        if (IntStd.IsNotIntThen(datainfo.GetValue("_lock")) == MetaLock.Lock)
        {
            return new
            {
                code = "failed",
                msg = "该资料已锁定"
            };
        }
        //查看当前操作是否符合过滤条件的要求
        if (where_fixed_filter_express != null)
        {
            FrameDLRObject express = FrameDLRObject.CreateInstance(@"{
$acttype : 'Query'
                }", EFFC.Frame.Net.Base.Constants.FrameDLRFlags.SensitiveCase);
            express.SetValue("$table", tablename);
            where_fixed_filter_express.SetValue("_default_pk", pk);
            express.SetValue("$where", where_fixed_filter_express);
            var result = DB.Excute(up, express, true);
            if (result.QueryTable.RowLength <= 0)
            {
                return new
                {
                    code = "failed",
                    msg = "当前资料不符合操作要求"
                };
            }
        }
        //data栏位类型过滤
        ConvertData2DBType(data, info);
        //增加操作者的信息
        data.SetValue("last_id", TokenPayLoad.ID);
        data.SetValue("last_ip", ClientInfo.IP);
        data.SetValue("last_name", TokenPayLoad["username"]);
        data.SetValue("last_time", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
        DB.QuickUpdate(up, tablename, data, new
        {
            _default_pk = pk
        });

        CommitTrans();
        return new
        {
            code = "success",
            msg = "操作成功"
        };
    }

    [EWRARoute("patch", "/md_form/{id}/{pk}/active")]
    [EWRARouteDesc("启用")]
    [EWRAAddInput("id", "string", "元数据表uid", "无默认值", EFFC.Frame.Net.Base.Constants.RestInputPosition.Path, false)]
    [EWRAAddInput("pk", "string", @"待删除的数据的_default_pk值", "无默认值", EFFC.Frame.Net.Base.Constants.RestInputPosition.PostData, false)]
    [EWRAAddInput("fixed_filter_express", "string", @"固定过滤条件表达式，采用DBExpress的$where表达式写法，传入时采用base64+urlcode编码方式；
表达式中可以使用一些基础变量，如下：
__login_id:当前登录者ID,
__login_name:当前登录者的登录名称
__user_no:登录信息中的userno值,
__no:登录信息中的no值,
__user_name:登录信息中的username值,
__user_type:登录信息中的usertype值,
__role_no:当前登录者系统角色编号，多个,
__role_name:当前登录者系统角色名称，多个,
__now:当前时间，格式yyyy-MM-dd HH:mm:ss
", "无默认值", EFFC.Frame.Net.Base.Constants.RestInputPosition.PostData, true)]
    [EWRAAddInput("fixed_data_express", "string", @"固定更新数据条件表达式，采用DBExpress的栏位表达式写法，传入时采用base64+urlcode编码方式；
表达式中可以使用一些基础变量，如下：
__login_id:当前登录者ID,
__login_name:当前登录者的登录名称
__user_no:登录信息中的userno值,
__no:登录信息中的no值,
__user_name:登录信息中的username值,
__user_type:登录信息中的usertype值,
__role_no:当前登录者系统角色编号，多个,
__role_name:当前登录者系统角色名称，多个,
__now:当前时间，格式yyyy-MM-dd HH:mm:ss
", "无默认值", EFFC.Frame.Net.Base.Constants.RestInputPosition.PostData, true)]
    [EWRAOutputDesc("返回结果", @"{
code:'success-成功，failed-失败',
msg:'提示信息'
}")]
    public object Active(string id, string pk)
    {
        string fixed_filter_express = ComFunc.UrlDecode(ComFunc.IsBase64Then(PostDataD.fixed_filter_express));
        string fixed_data_express = ComFunc.UrlDecode(ComFunc.IsBase64Then(PostDataD.fixed_data_express));

        var where_fixed_filter_express = parseFixedExpress(fixed_filter_express);
        var data = parseFixedExpress(fixed_data_express);

        if (fixed_filter_express != "" && where_fixed_filter_express == null)
        {
            return new
            {
                code = "failed",
                msg = "fixed_filter_express格式不正确"
            };
        }
        if (fixed_data_express != "" && data == null)
        {
            return new
            {
                code = "failed",
                msg = "fixed_orderby_express格式不正确"
            };
        }
        if (data == null) data = FrameDLRObject.CreateInstance();
        data.SetValue("_active", 1);

        BeginTrans();
        var metaup = DB.NewMetaUnitParameter();
        var up = DB.NewDBUnitParameter();
        var info = MetaDataUtilities.GetAllTables(metaup).Where(w => (w.MetaUID == id || w.MetaName == id) && w.IsCreated).FirstOrDefault();
        if (info == null)
        {
            return new
            {
                code = "failed",
                msg = "元数据表不存在",
            };
        }
        string tablename = info.MetaName;

        var datalist = (from t in DB.LamdaTable(up, tablename, "a")
                        where t._default_pk == pk
                        select t).GetQueryList(up);
        if (datalist.Count <= 0)
        {
            return new
            {
                code = "failed",
                msg = "无该资料"
            };
        }
        //查看当前操作是否符合过滤条件的要求
        if (where_fixed_filter_express != null)
        {
            FrameDLRObject express = FrameDLRObject.CreateInstance(@"{
$acttype : 'Query'
                }", EFFC.Frame.Net.Base.Constants.FrameDLRFlags.SensitiveCase);
            express.SetValue("$table", tablename);
            where_fixed_filter_express.SetValue("_default_pk", pk);
            express.SetValue("$where", where_fixed_filter_express);
            var result = DB.Excute(up, express, true);
            if (result.QueryTable.RowLength <= 0)
            {
                return new
                {
                    code = "failed",
                    msg = "当前资料不符合提交要求"
                };
            }
        }

        FrameDLRObject datainfo = datalist.First();
        if (data.Keys.Where(w => !datainfo.Keys.Contains(w)).Count() > 0)
        {
            return new
            {
                code = "failed",
                msg = "栏位不匹配"
            };
        }
        if (BoolStd.IsNotBoolThen(datainfo.GetValue("_active")))
        {
            return new
            {
                code = "failed",
                msg = "该资料已启用"
            };
        }
        //data栏位类型过滤
        ConvertData2DBType(data, info);
        //增加操作者的信息
        data.SetValue("last_id", TokenPayLoad.ID);
        data.SetValue("last_ip", ClientInfo.IP);
        data.SetValue("last_name", TokenPayLoad["username"]);
        data.SetValue("last_time", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
        DB.QuickUpdate(up, tablename, data, new
        {
            _default_pk = pk
        });

        CommitTrans();
        return new
        {
            code = "success",
            msg = "操作成功"
        };
    }
    [EWRARoute("patch", "/md_form/{id}/{pk}/deactive")]
    [EWRARouteDesc("停用")]
    [EWRAAddInput("id", "string", "元数据表uid", "无默认值", EFFC.Frame.Net.Base.Constants.RestInputPosition.Path, false)]
    [EWRAAddInput("pk", "string", @"待删除的数据的_default_pk值", "无默认值", EFFC.Frame.Net.Base.Constants.RestInputPosition.PostData, false)]
    [EWRAAddInput("fixed_filter_express", "string", @"固定过滤条件表达式，采用DBExpress的$where表达式写法，传入时采用base64+urlcode编码方式；
表达式中可以使用一些基础变量，如下：
__login_id:当前登录者ID,
__login_name:当前登录者的登录名称
__user_no:登录信息中的userno值,
__no:登录信息中的no值,
__user_name:登录信息中的username值,
__user_type:登录信息中的usertype值,
__role_no:当前登录者系统角色编号，多个,
__role_name:当前登录者系统角色名称，多个,
__now:当前时间，格式yyyy-MM-dd HH:mm:ss
", "无默认值", EFFC.Frame.Net.Base.Constants.RestInputPosition.PostData, true)]
    [EWRAAddInput("fixed_data_express", "string", @"固定更新数据条件表达式，采用DBExpress的栏位表达式写法，传入时采用base64+urlcode编码方式；
表达式中可以使用一些基础变量，如下：
__login_id:当前登录者ID,
__login_name:当前登录者的登录名称
__user_no:登录信息中的userno值,
__no:登录信息中的no值,
__user_name:登录信息中的username值,
__user_type:登录信息中的usertype值,
__role_no:当前登录者系统角色编号，多个,
__role_name:当前登录者系统角色名称，多个,
__now:当前时间，格式yyyy-MM-dd HH:mm:ss
", "无默认值", EFFC.Frame.Net.Base.Constants.RestInputPosition.PostData, true)]
    [EWRAOutputDesc("返回结果", @"{
code:'success-成功，failed-失败',
msg:'提示信息'
}")]
    public object Deactive(string id, string pk)
    {
        string fixed_filter_express = ComFunc.UrlDecode(ComFunc.IsBase64Then(PostDataD.fixed_filter_express));
        string fixed_data_express = ComFunc.UrlDecode(ComFunc.IsBase64Then(PostDataD.fixed_data_express));

        var where_fixed_filter_express = parseFixedExpress(fixed_filter_express);
        var data = parseFixedExpress(fixed_data_express);

        if (fixed_filter_express != "" && where_fixed_filter_express == null)
        {
            return new
            {
                code = "failed",
                msg = "fixed_filter_express格式不正确"
            };
        }
        if (fixed_data_express != "" && data == null)
        {
            return new
            {
                code = "failed",
                msg = "fixed_orderby_express格式不正确"
            };
        }
        if (data == null) data = FrameDLRObject.CreateInstance();
        data.SetValue("_active", 0);

        BeginTrans();
        var metaup = DB.NewMetaUnitParameter();
        var up = DB.NewDBUnitParameter();
        var info = MetaDataUtilities.GetAllTables(metaup).Where(w => (w.MetaUID == id || w.MetaName == id) && w.IsCreated).FirstOrDefault();
        if (info == null)
        {
            return new
            {
                code = "failed",
                msg = "元数据表不存在",
            };
        }
        string tablename = info.MetaName;

        var datalist = (from t in DB.LamdaTable(up, tablename, "a")
                        where t._default_pk == pk
                        select t).GetQueryList(up);
        if (datalist.Count <= 0)
        {
            return new
            {
                code = "failed",
                msg = "无该资料"
            };
        }
        //查看当前操作是否符合过滤条件的要求
        if (where_fixed_filter_express != null)
        {
            FrameDLRObject express = FrameDLRObject.CreateInstance(@"{
$acttype : 'Query'
                }", EFFC.Frame.Net.Base.Constants.FrameDLRFlags.SensitiveCase);
            express.SetValue("$table", tablename);
            where_fixed_filter_express.SetValue("_default_pk", pk);
            express.SetValue("$where", where_fixed_filter_express);
            var result = DB.Excute(up, express, true);
            if (result.QueryTable.RowLength <= 0)
            {
                return new
                {
                    code = "failed",
                    msg = "当前资料不符合提交要求"
                };
            }
        }

        FrameDLRObject datainfo = datalist.First();
        if (data.Keys.Where(w => !datainfo.Keys.Contains(w)).Count() > 0)
        {
            return new
            {
                code = "failed",
                msg = "栏位不匹配"
            };
        }
        if (!BoolStd.IsNotBoolThen(datainfo.GetValue("_active")))
        {
            return new
            {
                code = "failed",
                msg = "该资料已启用"
            };
        }
        //data栏位类型过滤
        ConvertData2DBType(data, info);
        //增加操作者的信息
        data.SetValue("last_id", TokenPayLoad.ID);
        data.SetValue("last_ip", ClientInfo.IP);
        data.SetValue("last_name", TokenPayLoad["username"]);
        data.SetValue("last_time", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
        DB.QuickUpdate(up, tablename, data, new
        {
            _default_pk = pk
        });

        CommitTrans();
        return new
        {
            code = "success",
            msg = "操作成功"
        };
    }
    #endregion

    #region LocalFunction
    private void ConvertData2DBType(FrameDLRObject data, MetaDataUtilities.MetaTable info)
    {
        var fixed_columns = MetaDataUtilities.FixColumnsModel;

        var columns = info.columns.Where(w => !w.IsVirsual).ToList();
        columns.AddRange(fixed_columns);

        foreach (var cc in data.Keys)
        {
            if (cc == "_subs") continue;
            var dtype = ComFunc.nvl(columns.Where(cw => cw.MetaColumnName == cc).First().MetaDataType);
            data.SetValue(cc, convert2DBValue(data.GetValue(cc), dtype));
        }
    }
    #endregion
}
}
